
let deliveryObserver = null

import { deliveryTradeInfo } from './deliveryTrade.js'
import { deliveryBottomTabs } from '@/content-scripts/watch/trading/delivery.js'

export function createDelivery() {
    deliveryBottomTabs()
    if (deliveryObserver) deliveryObserver.disconnect();
    let previousValues = {
        tabsTypeValue: null
    };
    deliveryObserver = new MutationObserver(() => {

        const tabsBtn = document.querySelector('.buysell > .dealbox > .order-type-sw-outer > .order-type-sw > .active > span')
        // console.log(tabsBtn, 'wwwwwwwwwwwwwwwwww');


        // console.log(tradeTopType, 'rrrrrrrrrrrrrr');
        // console.log(tradeTopType.innerHTML, 'rrrrrrrrrrrrrr');

        const hasChanged =
            tabsBtn.innerHTML !== previousValues.tabsTypeValue

        if (tabsBtn && hasChanged) {
            previousValues = {
                tabsTypeValue: tabsBtn.innerHTML
            }
            deliveryTradeInfo(tabsBtn.innerHTML)
            // perpetualTradeInfo(previousValues)
            // Tranoverage(previousValues)
        }
    });
    deliveryObserver.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        characterData: true,
    });
}